/** 数据列表工具(分页，查询，排序)**/
//拼接列表参数
function get_list_paras(){
	//搜索支付串
	var str = '';
	var searchStr = get_search_paras();
	if(searchStr != ''){
		str += '&' + searchStr;
	}
	var sortStr = get_sort_paras();
	if(sortStr != ''){
		str += '&' + sortStr;
	}
	var pageStr = get_page_paras();
	if(pageStr != ''){
		str += '&' + pageStr;
	}
	return (str.length>0)?str.substring(1):'';
}
//拼接查询参数
function get_search_paras(){
	var str = '';
	var objs = $('[list=search]');
	if(objs[0]){
		for(var i=0;i<objs.length;i++){
			if($(objs[i]).val() != ''){
				str += '&sh['+$(objs[i]).attr('lfield')+'][t]='+$(objs[i]).attr('ltype')
				str += '&sh['+$(objs[i]).attr('lfield')+'][v]='+$(objs[i]).val()
			}
		}
	}
	return (str.length>0)?str.substring(1):'';
}
//拼接排序参数
function get_sort_paras(){
	var str = '';
	var field = $('#sort_field').val();
    var val = $('#sort_val').val();
    if(field != '' && field != null){
    	return 'sort_field=' + field + '&sort_val=' + val;
    }
	return '';
}
//拼接分页参数
function get_page_paras(){
	var str = '';
	var maxresultobj = $('#max_result');
	if(maxresultobj[0]){
		str += '&maxresult='+ $(maxresultobj).val();
	}
	var pageobj = $('#page');
	if(pageobj[0]){
		str += '&page='+ $(pageobj).val();
	}
	return (str.length>0)?str.substring(1):'';
}

function to_html(){
	var paras = get_list_paras();
	window.location.href = page_url+(paras==''?'':('&'+paras));
}

$(function(){
	$('a[name=sort]').bind('click',function(){
		var field = $(this).attr('field');
		var hid_field = $('#sort_field').val();
	    var hid_val = $('#sort_val').val();
	    $('.sort_desc').remove();
	    $('.sort_asc').remove();
	    if(hid_field == field){
	    	if(hid_val == '1'){
	    		$('#sort_val').val('0');
	    		$(this).after('<span class="sort_desc"></span>');
	    	}else{
	    		$('#sort_val').val('1');
	    		$(this).after('<span class="sort_asc"></span>');
	    	}
	    }else{
	    	$('#sort_field').val(field);
	    	$('#sort_val').val('1');
    		$(this).after('<span class="sort_asc"></span>');
	    }
	    to_page(1);
	});
});
	
function to_page(page){
	$('#page').val(page);
	var paras = get_list_paras();
	window.location.href = page_url+(paras==''?'':('&'+paras));
}


